package com.shop.admin.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.stereotype.Repository;

import com.shop.admin.vo.AdminVO;
import com.shop.framework.util.Logger;

@Repository
public class AdminDAOImpl extends SqlSessionDaoSupport implements AdminDAO {

	@Override
	@SuppressWarnings("unchecked")
	public List<AdminVO.AdminMemberItem> listMember() {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		return getSqlSession().selectList("com.shop.admin.member.list", paramMap);
	}
	@Override
	public int isUserCnt(String id, String pw) {
		
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("id", id);
		paramMap.put("pw", pw);
		// 회원 등록 여부 판단
		int isUserCnt = (Integer)getSqlSession().selectOne("com.shop.admin.member.isUserCnt", paramMap);

		return isUserCnt;
	}
	
	@Override
	public int addMember(AdminVO.AdminMemberItem memberItem) {
		// TODO Auto-generated method stub
		int cnt = 0;

		cnt = (Integer)getSqlSession().insert("com.shop.admin.member.add", memberItem);
		
		Logger.getLogger().debug(this.getClass().getName() + " : " + this.getClass().getMethods()[0].getName());
		return cnt;
	}
	
	@Override
	public AdminVO.AdminMemberItem getMember(String seq) {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("seq", seq);
		
		return (AdminVO.AdminMemberItem)getSqlSession().selectOne("com.shop.admin.member.get", paramMap);
	}

	@Override
	public int updateMember(AdminVO.AdminMemberItem memberItem) {
		Logger.getLogger().debug(memberItem.getEmail());
		return getSqlSession().update("com.shop.admin.member.update", memberItem);
	}
	
	@Override
	public int deleteMember(String seq) {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("seq", seq);
		return getSqlSession().delete("com.shop.admin.member.delete", paramMap);
	}
}
